package learn.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 描述:
 *
 * @author Zhanggq
 * @date 2019/9/11 10:49
 */
@WebFilter(filterName = "testFilter",urlPatterns = "/myFilter")
public class EncodingFilter implements Filter {
    String encoding = null;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
        System.out.println("======filter init=====");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        if (encoding == null) {
//
//            request.getRequestDispatcher("/login.jsp").forward(request, response);
//        }
//        chain.doFilter(request, response);
        System.out.println("======filter doFilter=====");
    }

    @Override
    public void destroy() {
        System.out.println("======filter destroy=====");
    }
}
